VERSION 5.00
Begin VB.Form frmInvoiceKabala 
   Caption         =   "חשבונית מס/קבלה"
   ClientHeight    =   8115
   ClientLeft      =   60
   ClientTop       =   450
   ClientWidth     =   8820
   LinkTopic       =   "Form1"
   ScaleHeight     =   8115
   ScaleWidth      =   8820
   StartUpPosition =   3  'Windows Default
   Begin VB.TextBox txtTotalToBePaid 
      Alignment       =   1  'Right Justify
      Enabled         =   0   'False
      BeginProperty Font 
         Name            =   "MS Sans Serif"
         Size            =   9.75
         Charset         =   177
         Weight          =   700
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   285
      Left            =   6120
      TabIndex        =   83
      Text            =   "0.00"
      Top             =   4440
      Width           =   975
   End
   Begin VB.TextBox datInvoiceDate 
      Alignment       =   1  'Right Justify
      Height          =   285
      Left            =   360
      TabIndex        =   0
      Top             =   120
      Width           =   975
   End
   Begin VB.TextBox txtCheck 
      Height          =   285
      Index           =   2
      Left            =   2040
      TabIndex        =   43
      Top             =   6240
      Width           =   735
   End
   Begin VB.TextBox txtCheck 
      Height          =   285
      Index           =   1
      Left            =   2040
      TabIndex        =   36
      Top             =   5880
      Width           =   735
   End
   Begin VB.TextBox txtCheck 
      Height          =   285
      Index           =   0
      Left            =   2040
      TabIndex        =   29
      Top             =   5520
      Width           =   735
   End
   Begin VB.ComboBox lstPmtTypes 
      Height          =   315
      Index           =   0
      ItemData        =   "frmInvoiceKabala.frx":0000
      Left            =   7320
      List            =   "frmInvoiceKabala.frx":0022
      TabIndex        =   25
      Text            =   "1-מזומן"
      Top             =   5520
      Width           =   1215
   End
   Begin VB.TextBox txtTax 
      Alignment       =   1  'Right Justify
      Height          =   285
      Left            =   240
      TabIndex        =   47
      Text            =   "0.00"
      Top             =   6960
      Width           =   1095
   End
   Begin VB.TextBox txtAccount 
      Alignment       =   1  'Right Justify
      Height          =   285
      Index           =   2
      Left            =   5160
      TabIndex        =   40
      Top             =   6240
      Width           =   2055
   End
   Begin VB.TextBox txtBranch 
      Height          =   285
      Index           =   2
      Left            =   4200
      TabIndex        =   41
      Top             =   6240
      Width           =   855
   End
   Begin VB.TextBox txtCheckDate 
      Height          =   285
      Index           =   2
      Left            =   1080
      TabIndex        =   44
      Top             =   6240
      Width           =   855
   End
   Begin VB.TextBox txtAccount 
      Alignment       =   1  'Right Justify
      Height          =   285
      Index           =   1
      Left            =   5160
      TabIndex        =   33
      Top             =   5880
      Width           =   2055
   End
   Begin VB.TextBox txtBranch 
      Height          =   285
      Index           =   1
      Left            =   4200
      TabIndex        =   34
      Top             =   5880
      Width           =   855
   End
   Begin VB.TextBox txtCheckDate 
      Height          =   285
      Index           =   1
      Left            =   1080
      TabIndex        =   37
      Top             =   5880
      Width           =   855
   End
   Begin VB.TextBox txtCheckDate 
      Height          =   285
      Index           =   0
      Left            =   1080
      TabIndex        =   30
      Top             =   5520
      Width           =   855
   End
   Begin VB.TextBox txtBranch 
      Height          =   285
      Index           =   0
      Left            =   4200
      TabIndex        =   27
      Top             =   5520
      Width           =   855
   End
   Begin VB.TextBox txtAccount 
      Alignment       =   1  'Right Justify
      Height          =   285
      Index           =   0
      Left            =   5160
      TabIndex        =   26
      Top             =   5520
      Width           =   2055
   End
   Begin VB.TextBox txtAmount 
      Alignment       =   1  'Right Justify
      Height          =   285
      Index           =   2
      Left            =   240
      TabIndex        =   45
      Text            =   "0.00"
      Top             =   6240
      Width           =   735
   End
   Begin VB.TextBox txtAmount 
      Alignment       =   1  'Right Justify
      Height          =   285
      Index           =   1
      Left            =   240
      TabIndex        =   38
      Text            =   "0.00"
      Top             =   5880
      Width           =   735
   End
   Begin VB.TextBox txtAmount 
      Alignment       =   1  'Right Justify
      Height          =   285
      Index           =   0
      Left            =   240
      TabIndex        =   31
      Text            =   "0.00"
      Top             =   5520
      Width           =   735
   End
   Begin VB.ComboBox lstBanks 
      Height          =   315
      Index           =   0
      ItemData        =   "frmInvoiceKabala.frx":0098
      Left            =   2880
      List            =   "frmInvoiceKabala.frx":00AB
      TabIndex        =   28
      Top             =   5520
      Width           =   1215
   End
   Begin VB.ComboBox lstBanks 
      Height          =   315
      Index           =   1
      ItemData        =   "frmInvoiceKabala.frx":00E6
      Left            =   2880
      List            =   "frmInvoiceKabala.frx":00F9
      TabIndex        =   35
      Top             =   5880
      Width           =   1215
   End
   Begin VB.ComboBox lstBanks 
      Height          =   315
      Index           =   2
      ItemData        =   "frmInvoiceKabala.frx":0134
      Left            =   2880
      List            =   "frmInvoiceKabala.frx":0147
      TabIndex        =   42
      Top             =   6240
      Width           =   1215
   End
   Begin VB.ComboBox lstPmtTypes 
      Height          =   315
      Index           =   1
      ItemData        =   "frmInvoiceKabala.frx":0182
      Left            =   7320
      List            =   "frmInvoiceKabala.frx":01A4
      TabIndex        =   32
      Text            =   "1-מזומן"
      Top             =   5880
      Width           =   1215
   End
   Begin VB.ComboBox lstPmtTypes 
      Height          =   315
      Index           =   2
      ItemData        =   "frmInvoiceKabala.frx":021A
      Left            =   7320
      List            =   "frmInvoiceKabala.frx":023C
      TabIndex        =   39
      Text            =   "1-מזומן"
      Top             =   6240
      Width           =   1215
   End
   Begin VB.TextBox txtTotalPmt 
      Alignment       =   1  'Right Justify
      Enabled         =   0   'False
      BeginProperty Font 
         Name            =   "MS Sans Serif"
         Size            =   9.75
         Charset         =   177
         Weight          =   700
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   285
      Left            =   240
      TabIndex        =   48
      Text            =   "0.00"
      Top             =   7320
      Width           =   1095
   End
   Begin VB.TextBox txtNetPmt 
      Alignment       =   1  'Right Justify
      Enabled         =   0   'False
      Height          =   285
      Left            =   240
      TabIndex        =   46
      Text            =   "0.00"
      Top             =   6600
      Width           =   1095
   End
   Begin VB.CommandButton cmdCancel 
      Caption         =   "יציאה"
      Height          =   375
      Left            =   120
      TabIndex        =   51
      Top             =   7680
      Width           =   975
   End
   Begin VB.CommandButton cmdOK 
      Caption         =   "צור חשבונית/קבלה"
      Height          =   375
      Left            =   1320
      TabIndex        =   50
      Top             =   7680
      Width           =   2295
   End
   Begin VB.ComboBox lstCustomers 
      Height          =   315
      Left            =   4680
      Style           =   2  'Dropdown List
      TabIndex        =   1
      Top             =   480
      Width           =   2535
   End
   Begin VB.TextBox txtItemDescription 
      Alignment       =   1  'Right Justify
      Height          =   285
      Index           =   0
      Left            =   6000
      TabIndex        =   5
      Top             =   2400
      Width           =   2535
   End
   Begin VB.TextBox txtUnitPrice 
      Height          =   285
      Index           =   0
      Left            =   5040
      TabIndex        =   6
      Top             =   2400
      Width           =   855
   End
   Begin VB.TextBox txtItemQty 
      Height          =   285
      Index           =   0
      Left            =   2400
      TabIndex        =   9
      Top             =   2400
      Width           =   615
   End
   Begin VB.TextBox txtItemQty 
      Height          =   285
      Index           =   1
      Left            =   2400
      TabIndex        =   14
      Top             =   2760
      Width           =   615
   End
   Begin VB.TextBox txtUnitPrice 
      Height          =   285
      Index           =   1
      Left            =   5040
      TabIndex        =   11
      Top             =   2760
      Width           =   855
   End
   Begin VB.TextBox txtItemDescription 
      Alignment       =   1  'Right Justify
      Height          =   285
      Index           =   1
      Left            =   6000
      TabIndex        =   10
      Top             =   2760
      Width           =   2535
   End
   Begin VB.TextBox txtItemQty 
      Height          =   285
      Index           =   2
      Left            =   2400
      TabIndex        =   19
      Top             =   3120
      Width           =   615
   End
   Begin VB.TextBox txtUnitPrice 
      Height          =   285
      Index           =   2
      Left            =   5040
      TabIndex        =   16
      Top             =   3120
      Width           =   855
   End
   Begin VB.TextBox txtItemDescription 
      Alignment       =   1  'Right Justify
      Height          =   285
      Index           =   2
      Left            =   6000
      TabIndex        =   15
      Top             =   3120
      Width           =   2535
   End
   Begin VB.TextBox txtDetails 
      Alignment       =   1  'Right Justify
      Height          =   285
      Left            =   360
      TabIndex        =   3
      Top             =   960
      Width           =   5415
   End
   Begin VB.TextBox txtComments 
      Alignment       =   1  'Right Justify
      Height          =   285
      Left            =   360
      TabIndex        =   4
      Top             =   1440
      Width           =   5415
   End
   Begin VB.CheckBox chkRound 
      Caption         =   "לעגל את הסכום הסופי:"
      Height          =   255
      Left            =   6360
      TabIndex        =   22
      Top             =   4080
      Width           =   2175
   End
   Begin VB.TextBox txtRebateNIS 
      Alignment       =   1  'Right Justify
      Height          =   285
      Left            =   6360
      TabIndex        =   20
      Text            =   "0.00"
      Top             =   3600
      Width           =   1095
   End
   Begin VB.TextBox txtRebatePercent 
      Alignment       =   1  'Right Justify
      Height          =   285
      Left            =   4440
      TabIndex        =   21
      Text            =   "0"
      Top             =   3600
      Width           =   495
   End
   Begin VB.CheckBox chkVAT 
      Caption         =   "לחייב מע""מ:"
      Height          =   255
      Left            =   4920
      TabIndex        =   23
      Top             =   4080
      Value           =   1  'Checked
      Width           =   1335
   End
   Begin VB.ComboBox lstTrxCodes 
      Height          =   315
      Left            =   360
      Style           =   2  'Dropdown List
      TabIndex        =   2
      Top             =   480
      Width           =   2655
   End
   Begin VB.CommandButton cmdOpenInvoice 
      Caption         =   "Command1"
      Height          =   375
      Left            =   6360
      TabIndex        =   53
      Top             =   7680
      Visible         =   0   'False
      Width           =   2055
   End
   Begin VB.CommandButton cmdOKXML 
      Caption         =   "צור חשבונית/קבלה ב-XML"
      Height          =   375
      Left            =   3840
      TabIndex        =   49
      Top             =   7680
      Width           =   2175
   End
   Begin VB.ComboBox lstCurrency 
      Height          =   315
      Index           =   0
      ItemData        =   "frmInvoiceKabala.frx":02B2
      Left            =   3960
      List            =   "frmInvoiceKabala.frx":02C5
      TabIndex        =   7
      Text            =   "NIS"
      Top             =   2400
      Width           =   975
   End
   Begin VB.TextBox txtRate 
      Height          =   285
      Index           =   0
      Left            =   3240
      TabIndex        =   8
      Text            =   "1.0"
      Top             =   2400
      Width           =   615
   End
   Begin VB.ComboBox lstCurrency 
      Height          =   315
      Index           =   1
      ItemData        =   "frmInvoiceKabala.frx":02E2
      Left            =   3960
      List            =   "frmInvoiceKabala.frx":02F5
      TabIndex        =   12
      Text            =   "NIS"
      Top             =   2760
      Width           =   975
   End
   Begin VB.TextBox txtRate 
      Height          =   285
      Index           =   1
      Left            =   3240
      TabIndex        =   13
      Text            =   "1.0"
      Top             =   2760
      Width           =   615
   End
   Begin VB.ComboBox lstCurrency 
      Height          =   315
      Index           =   2
      ItemData        =   "frmInvoiceKabala.frx":0312
      Left            =   3960
      List            =   "frmInvoiceKabala.frx":0325
      TabIndex        =   17
      Text            =   "NIS"
      Top             =   3120
      Width           =   975
   End
   Begin VB.TextBox txtRate 
      Height          =   285
      Index           =   2
      Left            =   3240
      TabIndex        =   18
      Text            =   "1.0"
      Top             =   3120
      Width           =   615
   End
   Begin VB.TextBox txtVAT 
      Alignment       =   1  'Right Justify
      Height          =   285
      Left            =   3240
      TabIndex        =   24
      Text            =   "0.00"
      Top             =   4080
      Width           =   495
   End
   Begin VB.Label Label30 
      Alignment       =   1  'Right Justify
      Caption         =   "סה""כ לתשלום:"
      Height          =   255
      Left            =   7200
      TabIndex        =   82
      Top             =   4440
      Width           =   1335
   End
   Begin VB.Label Label29 
      Alignment       =   1  'Right Justify
      Caption         =   "פרטי התשלום:"
      BeginProperty Font 
         Name            =   "MS Sans Serif"
         Size            =   8.25
         Charset         =   177
         Weight          =   700
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   255
      Left            =   6960
      TabIndex        =   81
      Top             =   4800
      Width           =   1575
   End
   Begin VB.Label Label28 
      Alignment       =   1  'Right Justify
      Caption         =   "תאריך:"
      Height          =   255
      Left            =   1440
      TabIndex        =   80
      Top             =   120
      Width           =   615
   End
   Begin VB.Label Label27 
      Alignment       =   1  'Right Justify
      Caption         =   "סוג התשלום"
      Height          =   255
      Left            =   7440
      TabIndex        =   79
      Top             =   5160
      Width           =   1095
   End
   Begin VB.Label Label26 
      Alignment       =   1  'Right Justify
      Caption         =   "שובר/שיק"
      Height          =   255
      Left            =   2160
      TabIndex        =   78
      Top             =   5160
      Width           =   855
   End
   Begin VB.Label Label25 
      Alignment       =   1  'Right Justify
      Caption         =   "אם הסכום הוא 0 המערכת תתעלם מהשורה"
      Height          =   255
      Left            =   4680
      TabIndex        =   77
      Top             =   6720
      Width           =   3855
   End
   Begin VB.Label Label24 
      Alignment       =   1  'Right Justify
      Caption         =   "ניכוי במקור:"
      Height          =   255
      Left            =   1560
      TabIndex        =   76
      Top             =   6960
      Width           =   1095
   End
   Begin VB.Label Label23 
      Alignment       =   1  'Right Justify
      Caption         =   "ת. פרעון/תוקף"
      Height          =   375
      Left            =   840
      TabIndex        =   75
      Top             =   5160
      Width           =   1215
   End
   Begin VB.Label Label22 
      Alignment       =   1  'Right Justify
      Caption         =   "סניף"
      Height          =   255
      Left            =   4320
      TabIndex        =   74
      Top             =   5160
      Width           =   615
   End
   Begin VB.Label Label21 
      Alignment       =   1  'Right Justify
      Caption         =   "מס' ח-ן/כרטיס"
      Height          =   255
      Left            =   6000
      TabIndex        =   73
      Top             =   5160
      Width           =   1335
   End
   Begin VB.Label Label20 
      Alignment       =   1  'Right Justify
      Caption         =   "סכום"
      Height          =   375
      Left            =   120
      TabIndex        =   72
      Top             =   5160
      Width           =   735
   End
   Begin VB.Label Label19 
      Alignment       =   1  'Right Justify
      Caption         =   "בנק"
      Height          =   255
      Left            =   3360
      TabIndex        =   71
      Top             =   5160
      Width           =   615
   End
   Begin VB.Label Label18 
      Alignment       =   1  'Right Justify
      Caption         =   "סה""כ שולם:"
      Height          =   255
      Left            =   1560
      TabIndex        =   70
      Top             =   7320
      Width           =   1095
   End
   Begin VB.Label Label17 
      Alignment       =   1  'Right Justify
      Caption         =   "סה""כ נטו:"
      Height          =   255
      Left            =   1560
      TabIndex        =   69
      Top             =   6600
      Width           =   1095
   End
   Begin VB.Label Label1 
      Alignment       =   1  'Right Justify
      Caption         =   "טופס יצירת חשבונית מס/קבלה"
      BeginProperty Font 
         Name            =   "MS Sans Serif"
         Size            =   12
         Charset         =   177
         Weight          =   700
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   375
      Left            =   4680
      TabIndex        =   68
      Top             =   120
      Width           =   3855
   End
   Begin VB.Label Label2 
      Alignment       =   1  'Right Justify
      Caption         =   "שם הלקוח:"
      Height          =   255
      Left            =   7440
      TabIndex        =   67
      Top             =   480
      Width           =   1095
   End
   Begin VB.Label Label3 
      Alignment       =   1  'Right Justify
      Caption         =   "תיאור הפריט"
      Height          =   255
      Left            =   7200
      TabIndex        =   66
      Top             =   1920
      Width           =   1335
   End
   Begin VB.Label Label4 
      Alignment       =   1  'Right Justify
      Caption         =   "מחיר הפריט (לפני מע""מ)"
      Height          =   375
      Left            =   5040
      TabIndex        =   65
      Top             =   1920
      Width           =   1095
   End
   Begin VB.Label Label5 
      Alignment       =   1  'Right Justify
      Caption         =   "כמות"
      Height          =   255
      Left            =   2280
      TabIndex        =   64
      Top             =   1920
      Width           =   615
   End
   Begin VB.Label Label6 
      Alignment       =   1  'Right Justify
      Caption         =   "פרטי החשבונית (לא מוצגים ללקוח):"
      Height          =   255
      Left            =   5400
      TabIndex        =   63
      Top             =   960
      Width           =   3135
   End
   Begin VB.Label Label7 
      Alignment       =   1  'Right Justify
      Caption         =   "הערות לחשבונית (מוצגות ללקוח):"
      Height          =   255
      Left            =   5880
      TabIndex        =   62
      Top             =   1440
      Width           =   2655
   End
   Begin VB.Label Label8 
      Alignment       =   1  'Right Justify
      Caption         =   "הנחה בש""ח:"
      Height          =   255
      Left            =   7200
      TabIndex        =   61
      Top             =   3600
      Width           =   1335
   End
   Begin VB.Label Label9 
      Alignment       =   1  'Right Justify
      Caption         =   "הנחה באחוזים:"
      Height          =   255
      Left            =   4920
      TabIndex        =   60
      Top             =   3600
      Width           =   1335
   End
   Begin VB.Label Label10 
      Alignment       =   1  'Right Justify
      Caption         =   "ההנחה בש""ח גוברת על ההנחה באחוזים."
      BeginProperty Font 
         Name            =   "MS Sans Serif"
         Size            =   8.25
         Charset         =   177
         Weight          =   400
         Underline       =   0   'False
         Italic          =   -1  'True
         Strikethrough   =   0   'False
      EndProperty
      Height          =   255
      Left            =   480
      TabIndex        =   59
      Top             =   3600
      Width           =   3375
   End
   Begin VB.Label Label11 
      Alignment       =   1  'Right Justify
      Caption         =   "אם הכמות היא 0 המערכת לא תוסיף את הפריט לחשבונית"
      BeginProperty Font 
         Name            =   "MS Sans Serif"
         Size            =   8.25
         Charset         =   177
         Weight          =   400
         Underline       =   0   'False
         Italic          =   -1  'True
         Strikethrough   =   0   'False
      EndProperty
      Height          =   975
      Left            =   240
      TabIndex        =   58
      Top             =   2400
      Width           =   2055
   End
   Begin VB.Label Label12 
      Alignment       =   1  'Right Justify
      Caption         =   "סיווג תנועה:"
      Height          =   255
      Left            =   3120
      TabIndex        =   57
      Top             =   480
      Width           =   1095
   End
   Begin VB.Label Label13 
      Alignment       =   1  'Right Justify
      Caption         =   "שער"
      Height          =   255
      Left            =   3240
      TabIndex        =   56
      Top             =   1920
      Width           =   495
   End
   Begin VB.Label Label14 
      Alignment       =   1  'Right Justify
      Caption         =   "מטבע"
      Height          =   255
      Left            =   4080
      TabIndex        =   55
      Top             =   1920
      Width           =   735
   End
   Begin VB.Label Label15 
      Alignment       =   1  'Right Justify
      Caption         =   "אחוז המע""מ:"
      Height          =   255
      Left            =   3480
      TabIndex        =   54
      Top             =   4080
      Width           =   1335
   End
   Begin VB.Label Label16 
      Alignment       =   1  'Right Justify
      Caption         =   "אם אחוז המעמ הוא 0 אזי כספית תשלוף אותו מהנתונים שלה."
      BeginProperty Font 
         Name            =   "MS Sans Serif"
         Size            =   8.25
         Charset         =   177
         Weight          =   400
         Underline       =   0   'False
         Italic          =   -1  'True
         Strikethrough   =   0   'False
      EndProperty
      Height          =   375
      Left            =   240
      TabIndex        =   52
      Top             =   4080
      Width           =   2895
   End
End
Attribute VB_Name = "frmInvoiceKabala"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit

Const MOD_NAME = "frmInvoiceKabala."
Dim m_iInvoiceNum As Long


Private Sub cmdCancel_Click()
On Error Resume Next
    Unload Me
End Sub

Private Sub cmdOK_Click()
Const FUNC_NAME = MOD_NAME & "cmdInvoice_Click"
10    On Error GoTo func_err
    
    Dim iCustomersID As Long
    Dim iTrxCodesID As Long
    Dim V
    Dim varLineItems(2) As CaspitAPI.LineItem
    Dim varReceiptLineItems(2) As CaspitAPI.ReceiptLineItem
    Dim objCaspit As CaspitAPI.Caspit
    
20        If lstCustomers.ListIndex < 0 Then
30      MyErrMsgBox "חובה לבחור בלקוח"
40      Exit Sub
50        End If
60        If Len(txtItemDescription(0).Text) = 0 Then
70      MyErrMsgBox "חובה להכניס תיאור פריט"
80      Exit Sub
90        End If
100       If Len(txtUnitPrice(0).Text) = 0 Then
110     MyErrMsgBox "חובה להכניס מחיר פריט"
120     Exit Sub
130       End If
140       If Len(txtItemQty(0).Text) = 0 Then
150     MyErrMsgBox "חובה להכניס כמות פריט"
160     Exit Sub
170       End If
    
180       V = Split(lstCustomers.List(lstCustomers.ListIndex), "-")
190       iCustomersID = V(UBound(V))
    
200       V = Split(lstTrxCodes.List(lstTrxCodes.ListIndex), "-")
210       iTrxCodesID = V(UBound(V))
    
    
220       Set objCaspit = New CaspitAPI.Caspit
    
    Dim I As Long
    
230       For I = 0 To 2
240     If Len(txtItemQty(I)) <> 0 Then
250         If CDbl(txtItemQty(I)) > 0 Then
260             Set varLineItems(I) = New CaspitAPI.LineItem
270             varLineItems(I).ItemDescription = txtItemDescription(I)
280             If Len(txtUnitPrice(I)) > 0 Then varLineItems(I).UnitPrice = CCur(txtUnitPrice(I))
290             If Len(txtItemQty(I)) > 0 Then varLineItems(I).ItemQuantity = CDbl(txtItemQty(I))
300             If Len(txtRate(I)) > 0 Then varLineItems(I).CurrencyRate = CDbl(txtRate(I))
310             varLineItems(I).ItemCurrency = lstCurrency(I).List(lstCurrency(I).ListIndex)
320             varLineItems(I).ChargeVAT = True
330         End If
340     End If
350       Next
    
    Dim clsReceiptLineItem As CaspitAPI.ReceiptLineItem
360       For I = 0 To 2
370     If CDbl(txtAmount(I)) <> 0 Then
380         Set clsReceiptLineItem = New CaspitAPI.ReceiptLineItem
390         With clsReceiptLineItem
400             .AccountNumber = txtAccount(I)
410             .Amount = txtAmount(I)
420             If Len(lstBanks(I)) > 0 Then .Bank = Split(lstBanks(I), "-")(0)
430             .Branch = txtBranch(I)
440             .Check = txtCheck(I)
450             If IsDate(txtCheckDate(I)) Then .CheckDate = CDate(txtCheckDate(I))
460             .PaymentTypesID = Split(lstPmtTypes(I), "-")(0)
470         End With
480         Set varReceiptLineItems(I) = clsReceiptLineItem
490     End If
500       Next
    
510       With objCaspit
520           .CaspitPath = g_strCaspitPath
530           .AccessPath = g_strAccessPath
540           .BusinessID = g_iBusinessID
550           .DebugMode = g_blnDebug
560       End With
    
570       m_iInvoiceNum = objCaspit.CreateInvoiceKabala(iCustomersID, datInvoiceDate, _
        txtComments, txtRebatePercent, txtRebateNIS, chkRound.Value, txtVAT, chkVAT.Value, _
        txtDetails, _
        iTrxCodesID, _
        varLineItems, _
        0, txtTax, 0, varReceiptLineItems)
    
580       Set objCaspit = Nothing
    
590       cmdOpenInvoice.Caption = "הצג חשבונית " & m_iInvoiceNum
600       cmdOpenInvoice.Visible = True
    
610       MyMsgBox "חשבונית " & m_iInvoiceNum & " נוצרה בהצלחה."
        
620   Exit Sub

func_err:
630       ErrMsgBox Err.Number, FUNC_NAME & "[" & Erl & "]" & "\" & Err.Source, Err.Description
640       Set objCaspit = Nothing
End Sub

Private Sub cmdOKXML_Click()
Const FUNC_NAME = MOD_NAME & "cmdOKXML_Click"
10    On Error GoTo func_err
    
    Dim iCustomersID As Long
    Dim iTrxCodesID As Long
    Dim objCaspit As CaspitAPI.Caspit
    Dim strXML As String
    
20        If lstCustomers.ListIndex < 0 Then
30      MyErrMsgBox "חובה לבחור בלקוח"
40      Exit Sub
50        End If
60        If Len(txtItemDescription(0).Text) = 0 Then
70      MyErrMsgBox "חובה להכניס תיאור פריט"
80      Exit Sub
90        End If
100       If Len(txtUnitPrice(0).Text) = 0 Then
110     MyErrMsgBox "חובה להכניס מחיר פריט"
120     Exit Sub
130       End If
140       If Len(txtItemQty(0).Text) = 0 Then
150     MyErrMsgBox "חובה להכניס מחיר פריט"
160     Exit Sub
170       End If
180       If lstTrxCodes.ListIndex < 0 Then
190     MyErrMsgBox "חובה לבחור בסיווג תנועה"
200     Exit Sub
210       End If
    
220       strXML = "<Caspit>" & vbCrLf & "<Document type=""InvoiceKabala"">" & vbCrLf
    
    Dim V
230       V = Split(lstCustomers.List(lstCustomers.ListIndex), "-")
240       iCustomersID = CLng(V(UBound(V)))
250       strXML = strXML & "<CustomerID>" & iCustomersID & "</CustomerID>" & vbCrLf
     
260       V = Split(lstTrxCodes.List(lstTrxCodes.ListIndex), "-")
270       iTrxCodesID = V(UBound(V))
280       strXML = strXML & "<TrxCodesID>" & iTrxCodesID & "</TrxCodesID>" & vbCrLf
    
290       strXML = strXML & "<DocDate>" & FormatXMLDate(datInvoiceDate) & "</DocDate>" & vbCrLf
300       strXML = strXML & "<DocComments>" & RXML(txtComments) & "</DocComments>" & vbCrLf
310       strXML = strXML & "<DocDetails>" & RXML(txtDetails) & "</DocDetails>" & vbCrLf
320       strXML = strXML & "<RebatePercent>" & txtRebatePercent & "</RebatePercent>" & vbCrLf
330       strXML = strXML & "<RebateAmount>" & txtRebateNIS & "</RebateAmount>" & vbCrLf
340       strXML = strXML & "<RoundTotal>" & (chkRound.Value = 1) & "</RoundTotal>" & vbCrLf
350       strXML = strXML & "<ChargeVAT>" & (chkVAT.Value = 1) & "</ChargeVAT>" & vbCrLf
360       strXML = strXML & "<VAT>" & txtVAT & "</VAT>" & vbCrLf
    
    Dim I As Long
    
370       strXML = strXML & vbCrLf & "<LineItems>"
380       For I = 0 To 2
390     If Len(txtItemQty(I)) > 0 Then
400         If CDbl(txtItemQty(I)) > 0 Then
410             strXML = strXML & vbCrLf & "<LineItem number=""" & I + 1 & """>"
420             strXML = strXML & vbCrLf & "<ItemDescription>" & RXML(txtItemDescription(I)) & "</ItemDescription>"
430             strXML = strXML & vbCrLf & "<ItemQuantity>" & txtItemQty(I) & "</ItemQuantity>"
440             strXML = strXML & vbCrLf & "<UnitPrice>" & txtUnitPrice(I) & "</UnitPrice>"
450             strXML = strXML & vbCrLf & "<Currency>" & lstCurrency(I).List(lstCurrency(I).ListIndex) & "</Currency>"
460             strXML = strXML & vbCrLf & "<CurrencyRate>" & txtRate(I) & "</CurrencyRate>"
470             strXML = strXML & vbCrLf & "<ChargeVAT>" & "True" & "</ChargeVAT>"
480             strXML = strXML & vbCrLf & "</LineItem>"
490         End If
500     End If
510       Next
520       strXML = strXML & vbCrLf & "</LineItems>" & vbCrLf
    
530       strXML = strXML & "<Receipt>" & vbCrLf
540       strXML = strXML & "<Total>" & txtTotalPmt & "</Total>" & vbCrLf
550       strXML = strXML & "<Tax>" & txtTax & "</Tax>" & vbCrLf
560       strXML = strXML & "<NetPmt>" & txtNetPmt & "</NetPmt>" & vbCrLf
        
570       strXML = strXML & vbCrLf & "<ReceiptLineItems>"
580       For I = 0 To 2
590     If Len(txtAmount(I)) > 0 Then
600     If CCur(txtAmount(I)) > 0 Then
610         strXML = strXML & vbCrLf & "<ReceiptLineItem number=""" & I + 1 & """>"
620         strXML = strXML & vbCrLf & "<AccountNumber>" & RXML(txtAccount(I)) & "</AccountNumber>"
630         strXML = strXML & vbCrLf & "<Amount>" & txtAmount(I) & "</Amount>"
640         If Len(lstBanks(I).Text) > 0 Then
650             strXML = strXML & vbCrLf & "<Bank>" & Split(lstBanks(I).Text, "-")(0) & "</Bank>"
660         Else
670             strXML = strXML & vbCrLf & "<Bank></Bank>"
680         End If
690         strXML = strXML & vbCrLf & "<Branch>" & txtBranch(I) & "</Branch>"
700         strXML = strXML & vbCrLf & "<Check>" & RXML(txtCheck(I)) & "</Check>"
710         strXML = strXML & vbCrLf & "<CheckDate>" & FormatXMLDate(txtCheckDate(I)) & "</CheckDate>"
720         strXML = strXML & vbCrLf & "<PaymentTypesID>" & Split(lstPmtTypes(I).Text, "-")(0) & "</PaymentTypesID>"
730         strXML = strXML & vbCrLf & "</ReceiptLineItem>"
740     End If
750     End If
760       Next
770       strXML = strXML & vbCrLf & "</ReceiptLineItems>"
780       strXML = strXML & vbCrLf & "</Receipt>"
    
790       strXML = strXML & vbCrLf & "</Document>" & vbCrLf & "</Caspit>"

800       Set objCaspit = New CaspitAPI.Caspit
810       With objCaspit
820           .CaspitPath = g_strCaspitPath
830           .AccessPath = g_strAccessPath
840           .BusinessID = g_iBusinessID
850           .DebugMode = g_blnDebug
860       End With
870       m_iInvoiceNum = objCaspit.CreateInvoiceKabalaXML(strXML)
    
880       Set objCaspit = Nothing
    
890       cmdOpenInvoice.Caption = "הצג חשבונית " & m_iInvoiceNum
900       cmdOpenInvoice.Visible = True
    
910       MyMsgBox "חשבונית " & m_iInvoiceNum & " נוצרה בהצלחה."
        
920   Exit Sub

func_err:
930       ErrMsgBox Err.Number, FUNC_NAME & "[" & Erl & "]" & "\" & Err.Source, Err.Description
940       Set objCaspit = Nothing
End Sub

Private Sub cmdOpenInvoice_Click()
Const FUNC_NAME = MOD_NAME & "cmdOpenInvoice_Click"
10    On Error GoTo func_err

    Dim objCaspit As CaspitAPI.Caspit
    
20        Set objCaspit = New CaspitAPI.Caspit
    
30        With objCaspit
40            .CaspitPath = g_strCaspitPath
50            .AccessPath = g_strAccessPath
60            .BusinessID = g_iBusinessID
70            .DebugMode = g_blnDebug
80        End With
    
90        Call objCaspit.DisplayInvoiceKabala(m_iInvoiceNum)
100       Set objCaspit = Nothing
110   Exit Sub

func_err:
120       ErrMsgBox Err.Number, FUNC_NAME & "[" & Erl & "]" & "\" & Err.Source, Err.Description
130       Unload Me
End Sub

Private Sub Form_Load()
      Const FUNC_NAME = MOD_NAME & "Form_Load"
10    On Error GoTo func_err

20        datInvoiceDate = Date
          
30        PopulateCustomers
          
40        PopulateTrxCodes

50    Exit Sub

func_err:
60        MyErrMsgBox "Error " & Err.Number & " in " & FUNC_NAME & "[" & Erl & "]" & "\" & Err.Source & ": " & Err.Description
70        Unload Me
End Sub

Private Sub PopulateCustomers()
      Const FUNC_NAME = MOD_NAME & "PopulateCustomers"
10    On Error GoTo func_err
          
          Dim V As Variant
          Dim S As String
          Dim I As Long
          
          Dim objCaspit As CaspitAPI.Caspit
          Dim objCustomer As CaspitAPI.Customer
          
20        Set objCaspit = New CaspitAPI.Caspit
          
30        With objCaspit
40            .CaspitPath = g_strCaspitPath
50            .AccessPath = g_strAccessPath
60            .BusinessID = g_iBusinessID
70            .DebugMode = g_blnDebug
80        End With
          
          'We could get the information in XML form
90        S = objCaspit.GetCustomersXML()
          
          'or in an array
100       V = objCaspit.GetCustomers()
          
110       Set objCaspit = Nothing
          
120       If IsEmpty(V) Then Exit Sub
          
130       If UBound(V) < 0 Then
140           Err.Raise 1040, "", "יש ליצור לקוחות לפני שיוצרים חשבונית"
150       End If
          
          'Skip לקוח מזדמן
160       For I = 0 To UBound(V)
170           Set objCustomer = V(I)
180            Call lstCustomers.AddItem(objCustomer.BusinessName & " - " & objCustomer.CustomersID)
190       Next

200   Exit Sub

func_err:
210       Err.Raise Err.Number, FUNC_NAME & "[" & Erl & "]" & "\" & Err.Source, Err.Description
220       Set objCaspit = Nothing
End Sub

Private Sub PopulateTrxCodes()
      Const FUNC_NAME = MOD_NAME & "PopulateTrxCodes"
10    On Error GoTo func_err
          
          Dim V As Variant
          Dim I As Long
          
          Dim objCaspit As CaspitAPI.Caspit
          Dim objTrxCode As CaspitAPI.TrxCode
          
20        Set objCaspit = New CaspitAPI.Caspit
          
30        With objCaspit
40            .CaspitPath = g_strCaspitPath
50            .AccessPath = g_strAccessPath
60            .BusinessID = g_iBusinessID
70        End With
80        V = objCaspit.GetTrxCodes()
          
90        Set objCaspit = Nothing
          
100       If UBound(V) < 1 Then
110           Err.Raise 1040, "", "יש ליצור לקוחות לפני שיוצרים חשבונית"
120       End If
          
          ' Use only Trx Codes which are income related (PLCodesID = 1)
130       For I = 1 To UBound(V)
140           Set objTrxCode = V(I)
150           If (objTrxCode.PLCodesID = 1) Then
160               Call lstTrxCodes.AddItem(objTrxCode.TrxCodeDescription & " - " & objTrxCode.TrxCodesID)
170           End If
180       Next

190   Exit Sub

func_err:
200       Err.Raise Err.Number, FUNC_NAME & "[" & Erl & "]" & "\" & Err.Source, Err.Description
210       Set objCaspit = Nothing
End Sub

Private Sub txtAmount_Change(Index As Integer)
On Error Resume Next
    txtNetPmt.Text = CCur(txtAmount(0)) + CCur(txtAmount(1)) + CCur(txtAmount(2))
    txtTotalPmt.Text = CCur(txtAmount(0)) + CCur(txtAmount(1)) + CCur(txtAmount(2)) + CCur(txtTax)
End Sub

'---------------------------------------------------------------------------------------
' Procedure : txtItemQty_Change
' Author    : Dror
' Date      : 21/06/2011
' Purpose   :
'---------------------------------------------------------------------------------------
Private Sub txtItemQty_Change(Index As Integer)
      Const FUNC_NAME = MOD_NAME & "txtItemQty_Change"
10    On Error GoTo func_Error
          Dim I As Long
          Dim ttl As Currency
          

20        For I = 0 To 2
30            ttl = ttl + MyCCur(txtUnitPrice(I)) * MyCCur(txtRate(I)) * MyCCur(txtItemQty(I))
40        Next
50        ttl = (ttl - IIf(txtRebateNIS = "0.00", ttl * CDbl(txtRebatePercent / 100), CCur(txtRebateNIS)))
60        If chkVAT.Value = 1 Then ttl = ttl * (1 + IIf(txtVAT = "0.00", g_fltVAT, CDbl(txtVAT) / 100))
70        txtTotalToBePaid.Text = ttl

80    Exit Sub

func_Error:
90        ErrMsgBox Err.Number, FUNC_NAME & "[" & Erl & "]" & "\" & Err.Source, Err.Description
End Sub

Private Sub txtRebateNIS_Change()
    txtItemQty_Change 0
End Sub

Private Sub txtTax_Change()
On Error Resume Next
    txtTotalPmt.Text = CCur(txtAmount(0)) + CCur(txtAmount(1)) + CCur(txtAmount(2)) + CCur(txtTax)
End Sub

Private Sub txtUnitPrice_Change(Index As Integer)
    txtItemQty_Change Index
End Sub
Private Sub chkVAT_Click()
    txtItemQty_Change 0
End Sub

Private Sub txtVAT_Change()
    txtItemQty_Change 0
End Sub
